<?php

namespace App\Service;

use App\Model\Column;
use Hyperf\DbConnection\Db;
use Hyperf\Snowflake\IdGeneratorInterface;
use Hyperf\Utils\ApplicationContext;
use Psr\Container\ContainerInterface;
use Hyperf\Di\Annotation\Inject;

class ColumnService extends BaseService
{

    public function get_list($params,$fields=['*'])
    {
        // 关键字：行业名称
        $type = $params['type']?$params['type']:'';
        $is_show = $params['is_show']?$params['is_show']:'';
        $type = $params['type']?$params['type']:'';
        $where = [];
        if($is_show){
            $where['is_show'] = $is_show;
        }
        if($type){
            $where['type'] = $type;
        }
        return Column::query()
                ->where($where)
                ->with('create_info')
                ->with('update_info')
                ->orderBy('sort','desc')
                ->select($fields);
    }

    //   新增单条
    public function insert(array  $insertData)
    {
        $id = Column::query()->insertGetId($insertData);
        return  true;
    }
    public function insertGetId(array  $insertData)
    {
        return Column::query()->insertGetId($insertData);
    }

//    更新
    public function update(array  $upData)
    {
        return Column::query()->where('id',$upData['id'])->update($upData);
    }

    public function info(int $id)
    {
        return  Column::query()->where('id',$id)
            ->with(['create_info','update_info','delete_info'])
            ->first();
    }
}